package cn.kgc.houseservice.service;


import cn.kgc.bean.Houseorder;
import cn.kgc.myhousemapper.mapper.HouseorderMapper;
import cn.kgc.service.HouseOrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Component
public class HouseOrderServiceImpl implements HouseOrderService {
    @Resource
    HouseorderMapper houseorderMapper;

    @Override
    public PageInfo<Houseorder> selectHouseOrders(Integer pageNum, Integer pageSize, Integer houseid, String orderno,Date startTime, Date endTime) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy("date desc");
   /*     HouseorderExample houseorderExample=new HouseorderExample();
        HouseorderExample.Criteria criteria = houseorderExample.createCriteria();
        if (houseid!=null&&houseid!=0){
            criteria.andHouseidEqualTo(houseid);
        }
        if (orderno!=null&&!orderno.equals("")){
            criteria.andOrdernoEqualTo(orderno);
        }
        if (startTime!=null&&!startTime.toString().equals("Mon Jun 06 00:00:00 CDT 1988")&&endTime!= null&&!endTime.equals("Mon Jun 06 00:00:00 CDT 1988")){
            criteria.andDateBetween(startTime,endTime);
        }
        List<Houseorder> houseorders = houseorderMapper.selectByExample(houseorderExample);*/
        Map<String,String> map=new HashMap<>();
        QueryWrapper<Houseorder> queryWrapper=new QueryWrapper<Houseorder>();
        if (houseid!=null&&houseid!=0){
            queryWrapper.eq("houseid",houseid);

        }
        if (orderno!=null&&!orderno.equals("")) {
            queryWrapper.eq("orderno",orderno);
        }
        if (startTime!=null&&!startTime.toString().equals("Mon Jun 06 00:00:00 CDT 1988")&&endTime!= null&&!endTime.equals("Mon Jun 06 00:00:00 CDT 1988")){
            queryWrapper.between("date",startTime,endTime);
        }

        List<Houseorder> houseorders=houseorderMapper.selectList(queryWrapper);;
        PageInfo<Houseorder> pageInfo=new PageInfo<>(houseorders);
        return pageInfo;

    }

    @Override
    public int deleteHouseOrder(Integer houseid) {
        return houseorderMapper.deleteById(houseid);
    }

    @Override
    public int addHouseOrder(Houseorder houseorder) {
        return houseorderMapper.insert(houseorder);
    }

    @Override
    public int update(Houseorder houseorder) {
        return houseorderMapper.updateById(houseorder);
    }
}
